package com.aysafety.iotdataplatformweb.services.geosound.impl;

import com.aysafety.core.DBDriver.hbase.HBaseDriver;
import com.aysafety.core.common.DateUtils;
import com.aysafety.iotdataplatformweb.dao.GeosoundDao;
import com.aysafety.iotdataplatformweb.services.geosound.GeoSoundService;
import com.safety.algorithm.eigenvalue.EigenvalueAlgorithm;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service public class GeoSoundServiceImpl implements GeoSoundService {

    private final Map<String, Object> geoSoundStructure = new HashMap<String, Object>() {
        {
            put("entId", "String");
            put("deviceId", "String");
            put("clientId", "String");
            put("emergoa", "Double");
            put("poklad", "Double");
            put("datetime", "Date");
            put("workingFace", "String");
            put("pos", "String");
            put("probePos", "String");
        }
    };
    private final Map<String, Object> cal = new HashMap<String, Object>() {
        {
            put("entId", "String");
            put("deviceId", "String");
            put("avgEmergoa", "Double");
            put("unitTime", "Integer");
            put("pulse", "Long");
            put("datetime", "Date");
            put("calType", "Integer");
            put("energyDeviation", "Double");
            put("pulseFactor", "Double");
            put("pulseDeviation", "Double");
            put("dailyEnergyDeviation", "Long");
            put("dailyPulseDeviation", "Long");
        }
    };
    private final Map<String, Object> dailycal = new HashMap<String, Object>() {
        {
            put("entId", "String");
            put("deviceId", "String");
            put("avgEmergoa", "Double");
            put("datetime", "Date");
            put("calType", "Integer");
            put("dailyEnergyDeviation", "Long");
            put("dailyPulseDeviation", "Long");
            put("totalEnergy", "Double");
            put("maxEnergy", "Double");
        }
    };
    private final Map<String, Object> warning = new HashMap<String, Object>() {
        {
            put("entId", "String");
            put("w1", "Double");
            put("deviceId", "String");
            put("fitness", "Double");
            put("datetime", "Date");
            put("last", "String");
        }
    };
    @Autowired GeosoundDao geosoundDao;

    @Override
    public long countByGeoSound(String mineId, String deviceId, String startTime, String endTime, int timeSpan,
        String timeUnit) throws Throwable {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "GeosoundRealTime");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        return geosoundDao.countByGeoSound(parram);
    }

    @Override public List<Map<String, Object>> queryRealTimeByGeoSound(String mineId, String deviceId, String startTime,
        String endTime, int timeSpan, String timeUnit, int page, int size, String startRow) throws Throwable {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        String newDeviceId = deviceId.replace("-", "_");
        parram.put("tableId", mineId + "." + "GeosoundRealTime"+"_"+newDeviceId);
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        if (0 == size) {
            parram.put("size", null);
        } else {
            parram.put("size", size);
        }
        List<Map<String, Object>> result = geosoundDao.queryRealTimeByDeviceId(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }

    @Override public List<Map<String, Object>> queryWeblargeEnergy(String mineId, String deviceId, String startTime,
        String endTime) throws Throwable {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "GeosoundRealTime");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        parram.put("emergoa", 100000.0);

        List<Map<String, Object>> result = geosoundDao.queryRealTimeByGeoSound(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }


    /**
     * @Description: 脉冲
     * @Param: [mineId, equipmentId, startTime, endTime, unitTime]
     * @return: java.util.List<java.util.Map                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.Object>>
     * @Author: ChengQi
     * @Date: 2018/12/23
     */
    @Override public List<Map<String, Object>> getWebPulse(String mineId, String equipmentId, String startTime,
        String endTime, int unitTime) throws Throwable {
        String startRow = "";
        String endRow = "";

        List<Map<String, Object>> conditions = new ArrayList<Map<String, Object>>();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("columnFamily", "pulse");
        parram.put("columnId", "entId");
        parram.put("valueType", "String");
        parram.put("value", mineId);
        parram.put("symbol", "EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", "pulse");
        parram.put("columnId", "deviceId");
        parram.put("valueType", "String");
        parram.put("value", equipmentId);
        parram.put("symbol", "EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", "pulse");
        parram.put("columnId", "datetime");
        parram.put("valueType", "Long");
        parram.put("value", DateUtils.fomatDateTime(startTime).getTime());
        parram.put("symbol", "GREATER_OR_EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", "pulse");
        parram.put("columnId", "datetime");
        parram.put("valueType", "Long");
        parram.put("value", DateUtils.fomatDateTime(endTime).getTime());
        parram.put("symbol", "LESS_OR_EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", "pulse");
        parram.put("columnId", "calType");
        parram.put("valueType", "Integer");
        parram.put("value", 1);
        parram.put("symbol", "EQUAL");
        conditions.add(parram);

        if (StringUtils.isNotBlank(startTime) && StringUtils.isBlank(startRow)) {
            endRow = String.valueOf(DateUtils.fomatDateTime(startTime).getTime()) + ".";
        }
        if (StringUtils.isNotBlank(endTime)) {
            startRow = String.valueOf(DateUtils.fomatDateTime(endTime).getTime()) + ".";
        }

        return HBaseDriver.queryData("CalGeoSound", conditions, -1, 100000, this.cal, startRow, endRow);
    }

    @Override
    public List<Map<String, Object>> daily(String mineId, String deviceId, String startTime, String endTime, int size)
        throws Throwable {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CalDailyGeoSound");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        //parram.put("size", size);
        List<Map<String, Object>> result = geosoundDao.queryDaily(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }

    @Override public long countDaily(String mineId, String deviceId, String startTime, String endTime) {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CalDailyGeoSound");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        return geosoundDao.countDaily(parram);
    }

    @Override
    public List<Map<String, Object>> queryCalPulse(String mineId, String deviceId, String startTime, String endTime,
        int timeSpan, int n, int size) {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CalGeoPulse");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        List<Map<String, Object>> result = geosoundDao.queryCalPulse(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }

    @Override
    public long countCalPulse(String mineId, String deviceId, String startTime, String endTime, int timeSpan, int n) {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CalGeoPulse");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        return geosoundDao.countCalPulse(parram);
    }



    /**
     * @Description: 综合预警
     * @Param: [mineId, startTime, endTime]
     * @return: java.util.List<java.util.Map                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               <                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.String                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               ,                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               java.lang.Object>>
     * @Author: ChengQi
     * @Date: 2019/1/3
     */
    @Override public Map<String, Object> comprehensiveWarning(String mineId, String startTime, String endTime)
        throws Throwable {

        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "GEOSOUNDWARNING");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        //parram.put("deviceId", "\'" + deviceId + "\'");
        List<Map<String, Object>> result = geosoundDao.dailyComprehensiveWarning(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }


        parram.put("tableId", "GEOSOUNDWARNINGSTUDY");
        List<Map<String, Object>> studys = geosoundDao.queryGeosoundWarningStudy(parram);

        double sumWi = 0.0;
        //double sumRi = 0.0;
        double maxR = 0.0;
        double maxW = 0.0;
        double sum = 0.0;
        for (int i=0; i<studys.size(); i++) {
            maxR = maxR > Double.parseDouble(studys.get(i).get("R1").toString()) ?
                    maxR :
                    Double.parseDouble(studys.get(i).get("R1").toString());
        }


        for (int i = 0; i < result.size(); i++) {

            maxW = maxW > Double.parseDouble(result.get(i).get("w").toString()) ?
                maxW :
                Double.parseDouble(result.get(i).get("w").toString());

            //sumRi = sumRi + Double.parseDouble(result.get(i).get("R1").toString());
        }

        for (int i = 0; i < result.size(); i++) {
            double w = Double.parseDouble(result.get(i).get("w").toString());
            //double r = Double.parseDouble(result.get(i).get("fitness").toString());
            double r = maxR;
            //sum = sum + EigenvalueAlgorithm.divide(w * r, maxW * sumRi, 0);
        }

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("R", maxR);
        map.put("W", maxW);
        map.put("result", result);
        return map;
    }

    @Override
    public List<Map<String, Object>> queryCalEmergoa(String mineId, String deviceId, String startTime, String endTime,
        int parseInt, int parseInt1, int size) {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CALGEOEMERGOA");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        //parram.put("size", size);
        List<Map<String, Object>> result = geosoundDao.queryCalEmergoa(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }

    @Override
    public long countCalEmergoa(String mineId, String deviceId, String startTime, String endTime, int parseInt,
        int parseInt1) {

        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "CALGEOEMERGOA");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + deviceId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        return geosoundDao.countCalEmergoa(parram);
    }



    public List<Map<String, Object>> assemblyConditions(String columnFamily, String entId, String deviceId,
        String startTime, String endTime, int calType) {
        List<Map<String, Object>> conditions = new ArrayList<Map<String, Object>>();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("columnFamily", columnFamily);
        parram.put("columnId", "entId");
        parram.put("valueType", "String");
        parram.put("value", entId);
        parram.put("symbol", "EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", columnFamily);
        parram.put("columnId", "deviceId");
        parram.put("valueType", "String");
        parram.put("value", deviceId);
        parram.put("symbol", "EQUAL");

        if (calType > 0) {
            parram = new HashMap<String, Object>();
            parram.put("columnFamily", columnFamily);
            parram.put("columnId", "calType");
            parram.put("valueType", "String");
            parram.put("value", calType);
            parram.put("symbol", "EQUAL");
            conditions.add(parram);
        }
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", columnFamily);
        parram.put("columnId", "datetime");
        parram.put("valueType", "Long");
        parram.put("value", DateUtils.fomatDateTime(startTime).getTime());
        parram.put("symbol", "GREATER_OR_EQUAL");
        conditions.add(parram);
        parram = new HashMap<String, Object>();
        parram.put("columnFamily", columnFamily);
        parram.put("columnId", "datetime");
        parram.put("valueType", "Long");
        parram.put("value", DateUtils.fomatDateTime(endTime).getTime());
        parram.put("symbol", "LESS_OR_EQUAL");
        conditions.add(parram);
        return conditions;
    }


    /**
     * 查询脉冲、累积能量和能量均值
     * @param mineId
     * @param equipmentId
     * @param startTime
     * @param endTime
     * @param timeSpan
     * @param n
     * @param size
     * @return
     */
    @Override
    public List<Map<String, Object>> queryPluseAndEnergy(String mineId, String equipmentId, String startTime, String endTime, int timeSpan, int n, int size) {
        long startTimeTimestamp = DateUtils.fomatDateTime(startTime).getTime();
        long endTimeTimestamp = DateUtils.fomatDateTime(endTime).getTime();
        Map<String, Object> parram = new HashMap<String, Object>();
        parram.put("tableId", mineId + "." + "GeosoundPulseAndEnergy");
        parram.put("entId", "\'" + mineId + "\'");
        parram.put("deviceId", "\'" + equipmentId + "\'");
        parram.put("startTime", startTimeTimestamp);
        parram.put("endTime", endTimeTimestamp);
        List<Map<String, Object>> result = geosoundDao.queryGeosoundPluseAndEnergy(parram);
        for (int i = 0; i < result.size(); i++) {
            long timestamp = (long) result.get(i).get("datetime");
            Date dateTime = DateUtils.fomatDateTime(timestamp);
            result.get(i).put("datetime", DateUtils.getTime(dateTime));
        }
        return result;
    }
}
